package cn.wolfcode.controller;

import cn.wolfcode.domain.Region;
import cn.wolfcode.domain.StrategyCatalog;
import cn.wolfcode.query.StrategyCatalogQuery;
import cn.wolfcode.repository.StrategyCatalogRepository;
import cn.wolfcode.service.IDestinationService;
import cn.wolfcode.service.IStrategyCatalogService;
import cn.wolfcode.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IDestinationService destinationService;
    @RequestMapping("list")
    public Object list(Model model,StrategyCatalogQuery qo){
        Page query = strategyCatalogService.query(qo);
        model.addAttribute("qo",qo);
        model.addAttribute("page",query);
        return "/strategyCatalog/list";
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        if (!(strategyCatalog.getId() == null)){
            strategyCatalogService.update(strategyCatalog);
        }else {
            strategyCatalogService.insert(strategyCatalog);
        }
        return JsonResult.success();
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(String id){
        if (id != null){
            strategyCatalogService.delete(id);
            return JsonResult.success();
        }
        return JsonResult.defaultError();
    }
    
}
